<?php
/**
 * 
 * @author yusaint
 * @since 2014-3-23
 * @project Pfinal
 */
class Pfinal_Plugin_Orm_Kit {
	private $propertyMapping;
	private $entity;
	public function __construct($entity){
		$this->entity = $entity;
		$class = new ReflectionClass($entity);
		$properties = $class->getProperties(ReflectionProperty::IS_PUBLIC);
		if (!empty($properties)){
			foreach ($properties as $property) {
				$this->propertyMapping[$property->getName()] = $property;
			}
		}
		
	}	
	
	/**
	 * 
	 * @param unknown_type $row
	 * @return Pfinal_Plugin_Orm_Kit
	 */
	public function build($row){
		if (!empty($row)){
			foreach ($row as $field=>$value){
				if (!isset($this->propertyMapping[$field])){
					continue;
				}else{
					$this->propertyMapping[$field]->setValue($this->entity,$value);
				}
			}
		}	
		return $this->entity;	
	}
}

?>